package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user/shop")
@Api(tags = "用户查询营业状接口")
public class ShopUserController {
    //定义个常量，保存营业状态的 key
    public static final String key = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    //  查询营业状态
    @ApiOperation("查询营业状态")
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        //  从 Redis 中获取营业状态,get去出缓存数据
        Integer status = (Integer) redisTemplate.opsForValue().get(key);
        log.info("查询营业状态,当前营业状态为:{}",  status == 1 ? "营业中" : "打烊中");
        return Result.success(status);
    }

}
